package com.superhelper.common.utils;

public class GeoUtil {
    public static double calDist(Double lng1, Double lat1, Double lng2, Double lat2) {
        lng1 = lng1 == null ? 0 : lng1;
        lng2 = lng2 == null ? 0 : lng2;
        lat1 = lat1 == null ? 0 : lat1;
        lat2 = lat2 == null ? 0 : lat2;

        double radLat1 = Math.toRadians(lat1);
        double radLat2 = Math.toRadians(lat2);
        double a = radLat1 - radLat2;
        double b = Math.toRadians(lng1) - Math.toRadians(lng2);
        double s = 2 * Math.asin(Math.sqrt(
                Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
        s = s * 6378137.0;
        s = Math.round(s * 10000) / 10000;
        return s / 1000;
    }
}
